<?php
/**
 * Created by PhpStorm.
 * User: worry
 * Date: 2019/1/5
 * Time: 14:35
 */

use common\models\User;
use yii\widgets\LinkPager;
use \yii\helpers\ArrayHelper;
use \yii\helpers\Url;
?>
<style>
    .panel{border-bottom: 0;margin-top:5px;}
    .top10{margin-top:10px;}
</style>
<div class="row">
    <div class="col-lg-12 col-md-12 col-sm-12">
        <a href="/?id=<?= Yii::$app->user->getId() ?>" class="btn btn-info" target="_blank">业务员地址</a>&nbsp;&nbsp;&nbsp;&nbsp;<span
                class="text text-info"><?= Yii::$app->request->hostInfo ?>/?id=<?= Yii::$app->user->getId() ?></span>
    </div>
</div>
<div class="row">
    <div class="panel panel-default">
        <div class="panel-body">
            <form action="<?=Url::current()?>" class="form form-inline" method="post">
                <input type="hidden" name="<?=Yii::$app->request->csrfParam?>" value="<?=Yii::$app->request->csrfToken?>">
                <div class="form-group">
                    <label>姓名</label>
                    <input type="text" name="name" placeholder="请输入姓名" value="<?=ArrayHelper::getValue($search, 'name')?>" class="form-control">
                </div>
                <div class="form-group">
                    <label>手机号</label>
                    <input type="text" name="mobile" placeholder="请输入手机号" value="<?=ArrayHelper::getValue($search, 'mobile')?>" class="form-control">
                </div>
                <div class="form-group">
                    <label>提交时间</label>
                    <input type="text" name="start_date" placeholder="开始时间" value="<?=ArrayHelper::getValue($search, 'start_date')?>" class="form-control lay-date">
                    <input type="text" name="end_date" placeholder="结束时间" value="<?=ArrayHelper::getValue($search, 'end_date')?>" class="form-control lay-date">
                </div>
                <button type="submit" class="btn btn-primary">搜索</button>
            </form>
            <div class="form-group top10"><a href="<?=Url::to(array_merge(['/information/export'], $search))?>" target="_blank" class="btn btn-primary">导出数据</a></div>
            <table class="table table-bordered table-hover top10">
                <tr>
                    <th>ID</th>
                    <th>姓名</th>
                    <th>手机</th>
                    <th>业务员</th>
                    <th>提交时间</th>
                    <th>操作</th>
                </tr>
                <?php foreach ($list as $item): ?>
                    <tr>
                        <td><?= ArrayHelper::getValue($item, 'id') ?></td>
                        <td><?= ArrayHelper::getValue($item, 'name') ?></td>
                        <td><?= ArrayHelper::getValue($item, 'mobile') ?></td>
                        <?php $user = $item->hasOne(User::className(), ['id' => 'sale_id'])->one(); ?>
                        <td><?= $user ? $user->name : '-' ?></td>
                        <td><?= date('Y-m-d H:i', ArrayHelper::getValue($item, 'add_time')) ?></td>
                        <td>
                            <a href="<?= \yii\helpers\Url::to(['/information/edit', 'id' => ArrayHelper::getValue($item, 'id')]) ?>"
                               class="btn btn-primary">查看</a>
                            <button data-url="<?= \yii\helpers\Url::to(['/information/del', 'id' => ArrayHelper::getValue($item, 'id')]) ?>"
                                    class="btn btn-danger delete">删除
                            </button>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
        </div>
    </div>
</div>

<?= LinkPager::widget([
    'pagination' => $page,
]); ?>
<?php $this->registerJs('
$(".delete").click(function(){
    var url = $(this).attr("data-url");
    $.getJSON(url, function(resp){
        if(resp.status == 200) {
            location.reload();
        } else {
            alert(resp.message);
        }
    })
});
layui.use([\'laydate\', \'form\', \'layer\', \'upload\'], function(){
    var laydate = layui.laydate;
    //执行一个laydate实例
    laydate.render({
        elem: \'.lay-date\' //指定元素
    });
});
') ?>

